{extend name='public/base' /}

{block name="content"}



<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">商户：</label>
                        <div class="layui-input-inline">
                            <select name="merchant_id"  lay-search="" id="merchant_id">
                                <option value="" ></option>
                                {volist name="merchant_list" id="t"}
                                {if empty($t.name)||$t.name=='-'}
                                <option value="{$t.id}" >{$t.company} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {else/}
                                <option value="{$t.id}" >{$t.name} - {$t.code}-{$t.biz_state}-{$t.positions_code}</option>
                                {/if}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="overflow: inherit;">合同号：</label>
                        <div class="layui-input-inline">
                            <input name="code" class="layui-input" id="code" value="" type="text"
                                   placeholder="合同号">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search"
                                lay-submit="">
                            <i class="layui-icon" ></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i
                                class="layui-icon layui-icon-refresh"></i>{:__('Reset')}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="add"  class="layui-btn {:node('Proof/addAdmin')} layui-btn-sm">选择推送凭证</button>
        <button type="button" lay-event="deltoken"  class="layui-btn {:node('Proof/token')} layui-btn-sm">清除token</button>
    </div>
</script>
<script type="text/html" id="operationTpl">
    {{# if(d.id==0){ }}
    不可编辑
    {{# }else{ }}
<!--    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Admin/addAdmin')}" data-title="编辑"-->
<!--       lay-event="edit"><i class="layui-icon"></i></a>-->
<!--    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Admin/del')}" data-title="删除"-->
<!--       lay-event="del"><i class="layui-icon "></i></a>-->
    {{# } }}
</script>
<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'laydate','opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        form.render();
        laydate.render({
            elem: '#time1',
            range: true,
            trigger: 'click'
        });

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                // {title: '', type: 'checkbox', fixed: true},
                {title: 'ID', field: 'id',align: 'center',width:60},
                {title: '推送信息', field: 'company',templet:function (item){
                    if(item.merchant==null){
                        return item.push
                    }else {
                        return item.merchant.company
                    }

                    }},
                // {title: '合同号', field: 'code',templet:function (item){
                //         if(item.merchant==null){
                //             return item.push
                //         }else {
                //             return item.merchant.code
                //         }
                //
                //     }},
                {title: '类型', field: 'type',templet:function (item){
                    if(item.type==1){
                        return '电费记录推送凭证';
                    }else if(item.type==2){
                        return '充值记录推送凭证'
                    }else if(item.type==3){
                        return '水费记录推送凭证'
                    }else if(item.type==4){
                        return '余额转移推送凭证'
                    }else if(item.type==5){
                        return '月结凭证'
                    }else if(item.type==6){
                        return '余额缴费'
                    }else if(item.type==7){
                        return '转账缴费'
                    }else if(item.type==8){
                        return '线上缴费'
                    }else if(item.type==9){
                        return '账单负数转余额'
                    }
                        return '暂无'
                    }},
                {title: '返回信息', field: 'info'},
                {title: '推送时间',field: 'create_time',templet:function (item){
                        return layui.util.toDateString((item.create_time)*1000)
                    }},
                // {templet: '#operationTpl', width: 160, align: 'center', title: '操作'}

            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                var urls = "{:url('add')}?id=" + _id;
                lucky.CreateOpenForm("编辑", urls);

            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }else if (layEvent === "stop"){
                layer.confirm('确定停用?', {icon: 3, title:'提示'}, function(index){
                    var urls = "{:url('stop')}?id=" + _id;
                    $.get(urls,function (res) {
                        res = JSON.parse(res)
                        if (res.code == 1){
                            layer.msg(res.msg)
                            window.location.reload()
                            return
                        }else{
                            layer.msg(res.msg)
                        }

                    })
                });

            }if (layEvent === "start"){
                layer.confirm('确定启用?', {icon: 3, title:'提示'}, function(index){
                    var urls = "{:url('stop')}?id=" + _id;
                    $.get(urls,function (res) {
                        res = JSON.parse(res)
                        if (res.code == 1){
                            layer.msg(res.msg)
                            window.location.reload()
                            return
                        }else{
                            layer.msg(res.msg)
                        }

                    })
                });

            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("选择推送凭证", "{:url('add')}");
                return false;
            }if (obj.event === "deltoken") {
                lucky.FormSubmit("{:url('delToken')}");
                return false;
            }  else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "getWatch") {
                lucky.FormSubmit("{:url('getWatch')}");
            } else if (obj.event === "del") {

                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
